package us.gaaoc.framework.dao;

import org.hibernate.Query;

import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.DocumentType;
import us.gaaoc.framework.model.ExternalCaseRecordToCaseRecord;

public class ExternalCaseRecordToCaseRecordDAOHibernate extends
		GenericHibernateDAO<ExternalCaseRecordToCaseRecord, String, ExternalCaseRecordToCaseRecordDAO>
		implements ExternalCaseRecordToCaseRecordDAO {

	protected ExternalCaseRecordToCaseRecordDAOHibernate() {
	}

	public void insertExternalCaseRecordToCaseRecord(
			String externalCaseRecordUuid, CaseRecord caseRecord,
			int ocssCaseTypeCode) {
		LOG.info("Inside the insertExternalCaseRecord method of the ExternalCaseRecordDAOHibernate ....");
		ExternalCaseRecordToCaseRecord externalCaseRecord = new ExternalCaseRecordToCaseRecord();
		externalCaseRecord.setCaseRecord(caseRecord);
		externalCaseRecord.setExternalCaseRecordUuid(externalCaseRecordUuid);
		externalCaseRecord.setOcssCaseTypeCode(ocssCaseTypeCode);
		this.makePersistent(externalCaseRecord);

	}

	public CaseRecord findCaseRecordByExternalCaseRecordAndOCSSCaseTypeCode(
			String externaCaseRecordUuid, int ocssCaseTypeCode) {
		LOG.info("Inside the findCaseRecordByExternalCaseRecordAndOCSSTypeCode of ExternalCaseRecordDAOHibernate ...right before the query..");
		Query q = this.getSession().createQuery("from externalCaseRecordToCaseRecord ecr where ecr.externalCaseRecordUuid = ? and ecr.ocssCaseTypeCode = ? ");
		q.setString(0, externaCaseRecordUuid);
		q.setInteger(1, ocssCaseTypeCode);
		LOG.info("the query returned..");

		if (q.uniqueResult() == null) {
			LOG.info("The query returned no case records...");
			return null;
		} else {
			LOG.info("The query returned the following case record ...."
					+ q.uniqueResult().toString());
			return (CaseRecord) q.uniqueResult();
		}
	}
}
